package demo3;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.PriorityQueue;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 涛
 * Date: 2023-10-23
 * Time: 15:37
 */



//无返回值无参数
@FunctionalInterface
interface NoParameterNoReturn {
    void test();
}
//无返回值一个参数
@FunctionalInterface
interface OneParameterNoReturn {
    void test(int a);
}
//无返回值多个参数
@FunctionalInterface
interface MoreParameterNoReturn {
    void test(int a,int b);
}
//有返回值无参数
@FunctionalInterface
interface NoParameterReturn {
    int test();
}
//有返回值一个参数
@FunctionalInterface
interface OneParameterReturn {
    int test(int a);
}
//有返回值多参数
@FunctionalInterface
interface MoreParameterReturn {
    int test(int a,int b);
}
public class Test {
    public static void main(String[] args) {
        HashMap<Integer, String> map = new HashMap<>();
        map.put(1, "hello");
        map.put(2, "bit");
        map.put(3, "hello");
        map.put(4, "lambda");

//        map.forEach(new BiConsumer<Integer, String>() {
//            @Override
//            public void accept(Integer integer, String s) {
//                System.out.println("key:" + integer + " val:" + s);
//            }
//        });
        map.forEach((Integer key, String val) -> {System.out.println("key:" + key + " val:" + val);});

    }
    public static void main8(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("hello");
        list.add("lambda");
        list.add("Hello");
        list.add("bit");


//        list.forEach(new Consumer<String>() {
//            @Override
//            public void accept(String s) {
//                System.out.println(s);
//            }
//        });

        list.forEach((s) -> {System.out.println(s);});
        System.out.println("=====================");
//        list.sort(new Comparator<String>() {
//            @Override
//            public int compare(String o1, String o2) {
//                return o1.compareTo(o2);
//            }
//        });
        list.sort((o1, o2) -> {return o1.compareTo(o2);});
        list.forEach((s) -> {System.out.println(s);});


    }

    public static void main7(String[] args) {
        MoreParameterReturn moreParameterReturn = (int a, int b) -> {return a + b;};
        System.out.println(moreParameterReturn.test(1, 2));
    }
    public static void main6(String[] args) {
        OneParameterReturn oneParameterReturn = (a) -> {return a + 10;};
        System.out.println(oneParameterReturn.test(1));
    }
    public static void main5(String[] args) {
        NoParameterReturn noParameterReturn = () -> {return 10;};
        System.out.println(noParameterReturn.test());
    }
    public static void main4(String[] args) {
        MoreParameterNoReturn moreParameterNoReturn = (int a, int b) -> {System.out.println(a+b);};

        moreParameterNoReturn.test(10,20);
    }
    public static void main3(String[] args) {
        OneParameterNoReturn oneParameterNoReturn = (a) -> {System.out.println("OneParameterNoReturn " + a);};
        oneParameterNoReturn.test(10);
    }
    public static void main2(String[] args) {
        NoParameterNoReturn noParameterNoReturn = () -> System.out.println("重写了test方法");
        noParameterNoReturn.test();
    }
    public static void main1(String[] args) {
        NoParameterNoReturn noParameterNoReturn = new NoParameterNoReturn() {
            //一个内部类
            @Override
            public void test() {
                System.out.println("重写了方法");
            }
        };
        noParameterNoReturn.test();
        PriorityQueue<Integer> minHeap = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return 0;
            }
        });
        PriorityQueue<Integer> minHeap2 = new PriorityQueue<>((o1, o2) -> {return o1 - o2;});
    }
}
